<template>
  <div>
    <a-card :bordered='false'>
      <f-search-form :more='true' @searchHandler='searchHandler' :tableObj='tableObj' :show-export-btn='true' :exportUrl='api.erpSearch.exportSaleDetailList'>
        <f-search-form-item label='订单编号' name='orderNo' />
        <f-search-form-item label='批号' name='lotNo' />
        <f-search-form-item label='单位名称' name='customNo' type='select' :data='api.erpSearch.selectHyCustomList' :params='queryParam' value-key='customNo' label-key='customName' :show-all='false' :show-search='true' />
        <f-search-form-item label='单据日期' type='range' name='beginDate' slot='advanced' />
        <f-search-form-item label='商品名称' name='drugNo' type='select' slot='advanced' :data='api.erpSearch.selectDrugList' :params='queryParam' value-key='drugNo' :show-search='true' label-key='drugsName' />
        <f-search-form-item slot='advanced' label='部门名称' name='deptNo' type='select' :data='api.erpSearch.selectHyDeptList' :params='queryParam' value-key='deptNo' label-key='deptName' />

        <f-search-form-item slot='advanced' label='业务员' name='saleManBusinessNo' />
        <f-search-form-item slot='advanced' label='制单人' name='userName' />
      </f-search-form>
      <f-table ref='table' settingKey='saleDetailsList' rowKey='detailsId' :showSetting='true' :tableColumns='columns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.erpSearch.saleDetailList' handler='exportListHandler'>
         <span slot='ywfl' slot-scope='text, record, index'>
          <a-tag color='#FF0000' v-if='text=="ZS"'>
          招商
        </a-tag>
        <a-tag color='#00FF00' v-if='text=="ZY"'>
          自营
        </a-tag>
      </span>
        <span slot='orderNo' slot-scope='text, record, index'>
            <span v-clipboard:copy='text' v-clipboard:success='onCopy' style='cursor:pointer'>{{ text }}</span>
        </span>
        <span slot='saleType' slot-scope='text, record'>
        <template>
        <span>
           <a-tag v-if='text=="CKA"'>销售出库</a-tag>
            <a-tag v-if='text=="CKJ"'>销售退回</a-tag>
            <a-tag v-if='text=="CKI"'>退补差价</a-tag>
            <a-tag v-if='text=="CKB"'>调拨出库</a-tag>
            <a-tag v-if='text=="CKG"'>其他出库</a-tag>
            <a-tag v-if='text=="CKF"'>移出出库</a-tag>
            <a-tag v-if='text=="CKL"'>领用出库</a-tag>
            <a-tag v-if='text=="CKE"'>赠品出库</a-tag>
            <a-tag v-if='text=="CKC"'>报损出库</a-tag>
            <a-tag v-if='text=="CKD"'>盘亏出库</a-tag>

            <a-tag v-if='text=="RKB"'>采购验收</a-tag>
            <a-tag v-if='text=="RKN"'>进货退出</a-tag>
            <a-tag v-if='text=="RKM"'>退补差价</a-tag>
            <a-tag v-if='text=="RKF"'>商品损溢</a-tag>
            <a-tag v-if='text=="RKI"'>报升入库</a-tag>
            <a-tag v-if='text=="RKD"'>盘盈入库</a-tag>
            <a-tag v-if='text=="RKA"'>期初入库</a-tag>
        </span>
        </template>
      </span>
        <span slot='wsdj' slot-scope='text, record'>
          <template>
             <a @click='$refs.saleHistoryDrawer.showDrawer(record)'>{{ text }}</a>
          </template>
       </span>
      </f-table>
    </a-card>
    <sale-history-drawer ref='saleHistoryDrawer'></sale-history-drawer>
  </div>
</template>
<script>
import api from "./../../js/api"
import SaleHistoryDrawer from "./sale_history_drawer"

export default {
  name: "MingXiList",
  components: { SaleHistoryDrawer },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "更新参考成本价",
      icon: "plus",
      that: this,
      handler: (table, that) => {
        this.http.confirm(this, {
          content: "确认更新数据吗?",
          url: api.erpSearch.updateCostPrice,
          success: (me, data) => {
            this.$refs.table.refresh()
          }
        })
      }
    })
    let customFlag = this.$store.state.user.customFlag
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        companyId: this.$store.state.user.companyId
      },
      tableObj: null,
      superAdmin: this.superAdmin,
      // 表头
      columns: [
        {
          title: "序号",
          width: "70px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "单据日期",
          width: "100px",
          fixed: "left",
          dataIndex: "orderDate"
        },
        {
          title: "订单编号",
          align: "left",
          width: "130px",
          fixed: "left",
          dataIndex: "orderNo",
          scopedSlots: { customRender: "orderNo" }
        },
        {
          title: "单位名称",
          align: "left",
          width: "80px",
          length: 30,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "部门名称",
          align: "left",
          width: "80px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "80px",
          dataIndex: "businessNo"
        },
        {
          title: "商品名称",
          align: "left",
          width: "75px",
          dataIndex: "spmc"
        },
        {
          title: "规格",
          align: "left",
          width: "120px",
          length: 30,
          ellipsis: true,
          dataIndex: "gg"
        },
        {
          title: "批号",
          align: "left",
          width: "70px",
          dataIndex: "ph"
        },
        {
          title: "件容",
          align: "left",
          width: "70px",
          dataIndex: "jr"
        },
        {
          title: "数量",
          align: "left",
          width: "70px",
          dataIndex: "sl"
        },
        {
          title: "销售单价",
          align: "left",
          width: "70px",
          dataIndex: "hsdj"
        },

        {
          title: "销售金额",
          align: "left",
          width: "70px",
          dataIndex: "hsje"
        },
        {
          title: "件数",
          align: "left",
          width: "70px",
          dataIndex: "js"
        },
        {
          title: "参考成本",
          align: "left",
          width: "70px",
          dataIndex: "wsdj",
          scopedSlots: { customRender: "wsdj" }
        },
        {
          title: "成本单价",
          align: "left",
          width: "70px",
          dataIndex: "costPrice",
          customCell: this.renderTdBackground
        },
        {
          title: "成本金额",
          align: "left",
          width: "70px",
          dataIndex: "wsje"
        },
        {
          title: "效期",
          align: "left",
          width: "100px",
          dataIndex: "xq"
        },

        {
          title: "业务分类",
          align: "left",
          width: "100px",
          dataIndex: "ywfl",
          scopedSlots: { customRender: "ywfl" },
          filters: [
            {
              text: "招商",
              value: "ZS"
            },
            {
              text: "自营",
              value: "ZY"
            }
          ],
          filterMultiple: false
        },
        {
          title: "生产企业",
          align: "left",
          width: "120px",
          ellipsis: true,
          dataIndex: "scqy"
        },
        {
          title: "上市许可持有人",
          align: "left",
          width: "120px",
          ellipsis: true,
          dataIndex: "cyr"
        },
        {
          title: "单位",
          align: "left",
          width: "70px",
          dataIndex: "dw"
        },
        {
          title: "有效期至",
          align: "left",
          width: "70px",
          dataIndex: "yxqz"
        },
        {
          title: "生产日期",
          align: "left",
          width: "70px",
          dataIndex: "scrq"
        },
        {
          title: "制单人",
          align: "left",
          width: "100px",
          dataIndex: "userName"
        },
        {
          title: "方式名称",
          align: "left",
          width: "80px",
          dataIndex: "saleType",
          scopedSlots: { customRender: "saleType" }
        },
        {
          title: "备注",
          align: "left",
          width: "100px",
          dataIndex: "br"
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  mounted() {
    this.tableObj = this.$refs.table
  },
  methods: {
    renderTdBackground(record, flag) {
      if (record.wsdj != record.costPrice) {
        return {
          style: {
            "background-color": "rgb(255,150,150)"
          }
        }
      }
    },
    onCopy() {
      this.$message.success("复制成功!")
    },
    initSettle(record) {
      // this.http.confirm(this, {
      //   content: '确认初始化结算吗?',
      //   url: api.payment.initSettlePayment,
      //   data: {
      //     orderDetailsId: record.orderDetailsId
      //   }
      // })
    },
    clearExport() {
      this.http.post(this, {
        url: this.api.bod.clearExportData
      })
    }
  }
}
</script>
